package dnl.utils.jdbc.impexp;

import dnl.persistence.CsvToJdbcImporter;
import dnl.persistence.TableInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author Daniel Orr
 */
@Component
public class JdbcImportPg {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    DataSource importDataSource;

    void importData() {
        final File targetDir = new File("C:\\temp\\export1020-old");
        MetadataRegistry metadataRegistry = MetadataRegistry.fromFile(targetDir);
        JdbcImport jdbcImport = new JdbcImport(importDataSource, targetDir);
        try {
            jdbcImport.importTableData();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-pg.xml");
        final JdbcImportPg jdbcImportPg = (JdbcImportPg) applicationContext.getBean("jdbcImportPg");
        jdbcImportPg.importData();
    }
}
